package com.platform.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.platform.comm.validation.groups.Insert;
import com.platform.enums.FunctionStatus;
import com.platform.enums.FunctionType;
import com.platform.comm.dto.BaseQo;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.List;


/**
 * Description: 菜单信息-DTO
 *
 * @author libin Created on 2019/7/18
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class FunctionQo extends BaseQo {
    private static final long serialVersionUID = 3787714287202488401L;
    /**
     * 菜单名称
     */
    @NotEmpty(message = "菜单名称不能为空", groups = Insert.class)
    @Size(max = 200, message = "菜单名称长度不能超过200个字符")
    private String name;

    /**
     * 上级菜单
     */
    private String parentId;

    /**
     * 菜单级别
     */
    private Integer level;

    /**
     * 排序编号
     */
    private Integer sortNum;

    /**
     * 菜单路径
     */
    @Size(max = 500, message = "菜单路径长度不能超过500个字符")
    private String url;

    /**
     * 信息状态
     */
    @Pattern(regexp = "[01YN]", message = "信息状态不合法")
    private FunctionStatus delFlag;

    /**
     * 菜单类型
     */
    @Size(max = 16, message = "菜单类型长度不能超过16个字符")
    @Pattern(regexp = "[123]", message = "菜单类型值不匹配")
    private FunctionType type;

    /**
     * 业务类型
     */
    private String bizType;

    /**
     * 菜单路由
     */

    @Size(max = 2048, message = "菜单路由长度不能超过2048个字符")
    private String route;

    /**
     * 所属管理域
     */
    @Size(max = 36, message = "所属管理域长度不能超过36个字符")
    private String domain;

    /**
     * 菜单前端路由
     */
    @Size(max = 500, message = "菜单前端路由长度不能超过500个字符")
    private String path;

    /**
     * 是否授权
     */
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private boolean authorized;

    List<FunctionQo> permissions;

    /**
     * 菜单用途描述
     */
    private String desc;

    /**
     * 菜单图标
     */
    private String icon;

    @Size(max = 255, message = "子系统编号")
    private String subSystemCode;

    @Size(max = 255, message = "子系统id")
    private String subSystemId;


    private String linkType = "route";

    @Override
    public void init() {
        super.init();
        if (this.getDelFlag() == null) {
            this.setDelFlag(FunctionStatus.Y);
        }
        if (this.getSortNum() == null) {
            this.setSortNum(0);
        }
    }
}
